<?php

namespace app\admin\controller\shop;

use app\common\controller\Backend;
use think\Db;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
use think\response\Json;

/**
 * 认证管理
 *
 * @icon fa fa-circle-o
 */
class Auth extends Backend
{

    /**
     * Auth模型对象
     * @var \app\admin\model\shop\Auth
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\shop\Auth;
        $this->view->assign("stateList", $this->model->getStateList());
        $this->view->assign("paymentList", $this->model->getPaymentList());
        $this->view->assign("receiptList", $this->model->getReceiptList());
        $this->view->assign("individualList", $this->model->getIndividualList());
        $this->view->assign("authorizationList", $this->model->getAuthorizationList());
        $this->view->assign("operationList", $this->model->getOperationList());
        $this->view->assign("guaranteeList", $this->model->getGuaranteeList());
        $this->view->assign("publiccontractList", $this->model->getPubliccontractList());
        $this->view->assign("orizationList", $this->model->getOrizationList());
        $this->view->assign("verifyList", $this->model->getVerifyList());
        $this->view->assign("statusList", $this->model->getStatusList());
    }



    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */
    /**
     * 查看
     *
     * @return string|Json
     * @throws \think\Exception
     * @throws DbException
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if (false === $this->request->isAjax()) {
            return $this->view->fetch();
        }
        //如果发送的来源是 Selectpage，则转发到 Selectpage
        if ($this->request->request('keyField')) {
            return $this->selectpage();
        }
        [$where, $sort, $order, $offset, $limit] = $this->buildparams();
        $list = $this->model
            ->with(['staff'])
            ->where($where)
            ->order($sort, $order)
            ->paginate($limit);
        $result = ['total' => $list->total(), 'rows' => $list->items()];
        return json($result);
    }

    public function detail($ids = null){

        $ids = $ids ?: $this->request->post("ids");
        if (empty($ids)) {
            $this->error(__('Parameter %s can not be empty', 'ids'));
        }

        $pk = $this->model->getPk();
        $adminIds = $this->getDataLimitAdminIds();
        if (is_array($adminIds)) {
            $this->model->where($this->dataLimitField, 'in', $adminIds);
        }

        $row = Db::name('wanlshop_auth w')->where('w.id',$ids)
                ->field('w.id,state,shopname,w.name,shop_code,phone,w.city,w.createtime,staff_id,number,s.name as staff_name,w.remark,w.verify,w.examinetime,w.examinehourtime,auditsuccessfultime,auth.examinetime as examinetime1,auth.createtime as authtime,auth.examinehourtime as auth_examinehourtime,w.examineid')
            ->join('staff s','s.id = w.staff_id','left')
            ->join('wanlshop_auth_financial auth','auth.wanlshop_auth_id = w.id','left')
            ->find();

        $rowStaff = Db::name('staff')->where('id',$row['examineid'])->find();
        if(isset($rowStaff['jobgrade'])){
            $rowStaff_job = Db::name('staff_job')->where('id',$rowStaff['jobgrade'])->value('name');
        }else{
            $rowStaff_job = '';
        }



        $band = [
            'createtime' =>'',
            'examinetime' =>'',
            'examinehourtime' =>'/',
            'verify'=>0,
            'examineid' =>'',
            'name' =>   '',
            'verify_text' =>0,
        ];

        // 财务
        $fid  = Db::name('wanlshop_auth_financial f')->where('f.wanlshop_auth_id',$ids)->value('id');
        $list  = Db::name('wanlshop_auth_financial f')->where('f.wanlshop_auth_id',$ids)
            ->join('staff s','s.id = f.examineid','left')
            ->find();

        if ($list){
            $listStaff = Db::name('staff_job')->where('id',$list['jobgrade'])->value('name');
        }else{
            $listStaff = '';
        }

        //选址
        $seid  = Db::name('wanlshop_auth_selection w')->where('w.wanlshop_auth_id',$ids)->value('id');
        $list1  = Db::name('wanlshop_auth_selection w')->where('w.wanlshop_auth_id',$ids)
            ->join('staff s','s.id = w.examineid','left')
            ->find();

        if (isset($list1['jobgrade'])){
            $list1Staff = Db::name('staff_job')->where('id',$list1['jobgrade'])->value('name');
        }else{
            $list1Staff = '';
        }

        if (!$list1){
            $list1 = $band;
        }
        // 装修设计
        $deid  = Db::name('wanlshop_auth_design d')->where('d.wanlshop_auth_id',$ids)->value('id');
        $list2  = Db::name('wanlshop_auth_design d')->where('d.wanlshop_auth_id',$ids)
            ->join('staff s','s.id = d.examineid','left')
            ->find();

        if (isset($list2['jobgrade'])){
            $list2Staff = Db::name('staff_job')->where('id',$list2['jobgrade'])->value('name');
        }else{
            $list2Staff = '';
        }
        if (!$list2){
            $list2 = $band;
        }

        // 订货下单
        $goid  = Db::name('wanlshop_auth_goods g')->where('g.wanlshop_auth_id',$ids)->value('id');
        $list3  = Db::name('wanlshop_auth_goods g')->where('g.wanlshop_auth_id',$ids)
            ->join('staff s','s.id = g.examineid','left')
            ->find();
        if (isset($list3['jobgrade'])){
            $list3Staff = Db::name('staff_job')->where('id',$list3['jobgrade'])->value('name');
        }else{
            $list3Staff = '';
        }
        if (!$list3){
            $list3 = $band;
        }

        // 供应链
        $supid  = Db::name('wanlshop_auth_supply su')->where('su.wanlshop_auth_id',$ids)->value('id');
        $list4  = Db::name('wanlshop_auth_supply su')->where('su.wanlshop_auth_id',$ids)
            ->join('staff s','s.id = su.examineid','left')
            ->find();
        if (isset($list4['jobgrade'])){
            $list4Staff = Db::name('staff_job')->where('id',$list4['jobgrade'])->value('name');
        }else{
            $list4Staff = '';
        }
        if (!$list4){
            $list4 = $band;
        }

        // 培训
        $trainid  = Db::name('wanlshop_auth_train tr')->where('tr.wanlshop_auth_id',$ids)->value('id');
        $list5  = Db::name('wanlshop_auth_train tr')->where('tr.wanlshop_auth_id',$ids)
            ->join('staff s','s.id = tr.examineid','left')
            ->find();
        if (!$list5){
            $list5 = $band;
        }
        if (isset($list5['jobgrade'])){
            $list5Staff = Db::name('staff_job')->where('id',$list5['jobgrade'])->value('name');
        }else{
            $list5Staff = '';
        }
        //  公益行
        $activityid  = Db::name('wanlshop_auth_activity ac')->where('ac.wanlshop_auth_id',$ids)->value('id');
        $list6  = Db::name('wanlshop_auth_activity ac')->where('ac.wanlshop_auth_id',$ids)
            ->join('staff s','s.id = ac.examineid','left')
            ->find();
        if (!$list6){
            $list6 = $band;
        }
        if (isset($list6['jobgrade'])){
            $list6Staff = Db::name('staff_job')->where('id',$list6['jobgrade'])->value('name');
        }else{
            $list6Staff = '';
        }
        // 待开业
        $businessid  = Db::name('wanlshop_auth_business bu')->where('bu.wanlshop_auth_id',$ids)->value('id');
        $list7  = Db::name('wanlshop_auth_business bu')->where('bu.wanlshop_auth_id',$ids)
            ->join('staff s','s.id = bu.examineid','left')
            ->find();
        if (!$list7){
            $list7 = $band;
        }
        if (isset($list7['jobgrade'])){
            $list7Staff = Db::name('staff_job')->where('id',$list7['jobgrade'])->value('name');
        }else{
            $list7Staff = '';
        }
        // 授权书
        $accreditid = Db::name('wanlshop_auth_accredit ac')->where('ac.wanlshop_auth_id',$ids)->value('id');
        $list8  = Db::name('wanlshop_auth_accredit acc')->where('acc.wanlshop_auth_id',$ids)
            ->join('staff s','s.id = acc.examineid','left')
            ->find();
        if (!$list8){
            $list8 = $band;
        }
        if (isset($list8['jobgrade'])){
            $list8Staff = Db::name('staff_job')->where('id',$list8['jobgrade'])->value('name');
        }else{
            $list8Staff = '';
        }
        //
        if (!$list){
            $list['verify'] = 0;
        }

        if ($row['verify'] == 0){
            $row['verify_text'] = '信息录入';
        }elseif ($row['verify'] == 1){
            $row['verify_text'] = '提交店铺';
        }elseif ($row['verify'] == 2){
            $row['verify_text'] = '提交审核';
        }elseif ($row['verify'] == 3){
            $row['verify_text'] = '通过';
        }elseif ($row['verify'] == 4){
            $row['verify_text'] = '未通过';
        }

        if ($row['state'] == 0){
            $row['state'] = '个人';
        }elseif ($row['state'] == 1){
            $row['state'] = '服务商';
        }elseif ($row['state'] == 2){
            $row['state'] = '门店';
        }
        $this->view->assign("row", $row);
        $this->view->assign("rowStaff", $rowStaff);
        $this->view->assign("rowStaff_job", $rowStaff_job);
        $this->view->assign("fid", $fid);
        $this->view->assign("list", $list);
        $this->view->assign("listStaff", $listStaff);
        $this->view->assign("seid", $seid);
        $this->view->assign("list1", $list1);
        $this->view->assign("list1Staff", $list1Staff);
        $this->view->assign("deid", $deid);
        $this->view->assign("list2", $list2);
        $this->view->assign("list2Staff", $list2Staff);
        $this->view->assign("goid", $goid);
        $this->view->assign("list3", $list3);
        $this->view->assign("list3Staff", $list3Staff);
        $this->view->assign("supid", $supid);
        $this->view->assign("list4", $list4);
        $this->view->assign("list4Staff", $list4Staff);
        $this->view->assign("trainid", $trainid);
        $this->view->assign("list5", $list5);
        $this->view->assign("list5Staff", $list5Staff);
        $this->view->assign("activityid", $activityid);
        $this->view->assign("list6", $list6);
        $this->view->assign("list6Staff", $list6Staff);
        $this->view->assign("businessid", $businessid);
        $this->view->assign("list7", $list7);
        $this->view->assign("list7Staff", $list7Staff);
        $this->view->assign("accreditid", $accreditid);
        $this->view->assign("list8", $list8);
        $this->view->assign("list8Staff", $list8Staff);
        return $this->view->fetch();
    }
    public function check()
    {
        $ids = $this->request->post('id');
        $time = $this->request->post('time');
        $type = $this->request->post('type');
        if (empty($ids)) {
            $this->error(__('Parameter %s can not be empty', 'ids'));
        }
        if ($type == 'finance'){
            $this->model = new \app\admin\model\shop\Financial();
        }elseif ($type == 'information'){
            $this->model = new \app\admin\model\shop\Auth();
        }elseif ($type == 'selection'){
            $this->model = new \app\admin\model\shop\Selection();
        }elseif ($type =='design'){
            $this->model = new \app\admin\model\shop\Design();
        }elseif ($type =='goods'){
            $this->model = new \app\admin\model\shop\Goods();
        }elseif ($type =='supply'){
            $this->model = new \app\admin\model\shop\Supply();
        }elseif ($type =='train'){
            $this->model = new \app\admin\model\shop\Train();
        }elseif ($type =='activity'){
            $this->model = new \app\admin\model\shop\Activity();
        }elseif ($type =='business'){
            $this->model = new \app\admin\model\shop\Business();
        }elseif ($type =='accredit'){
            $this->model = new \app\admin\model\shop\Accredit();
        }
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $result = false;

        Db::startTrans();
        try {
            if  ($type == 'information'){
                $data= ['examinetime' => time(),'examinehourtime' => $time,'verify'=>2];
            }else{
                $data= ['createtime'=>time(),'examinehourtime' => $time,'verify'=>1];
            }

            $result = $row->allowField(true)->save($data);
            if ($type == 'information'){
                // 给其他表增加记录 // 或者修改
                $list  = Db::name('wanlshop_auth_financial f')->where('f.wanlshop_auth_id',$ids)
                    ->join('staff s','s.id = f.examineid','left')
                    ->find();
                if (!$list){
                    //财务
                    Db::name('wanlshop_auth_financial')->insert(['wanlshop_auth_id' => $ids]);
                    //选址
                    Db::name('wanlshop_auth_selection')->insert(['wanlshop_auth_id' => $ids]);
                    //装修设计
                    Db::name('wanlshop_auth_design')->insert(['wanlshop_auth_id' => $ids]);
                    //订货下单
                    Db::name('wanlshop_auth_goods')->insert(['wanlshop_auth_id' => $ids]);
                    //供应链
                    Db::name('wanlshop_auth_supply')->insert(['wanlshop_auth_id' => $ids]);
                    //培训
                    Db::name('wanlshop_auth_train')->insert(['wanlshop_auth_id' => $ids]);
                    //公益行
                    Db::name('wanlshop_auth_activity')->insert(['wanlshop_auth_id' => $ids]);
                    //待开业
                    Db::name('wanlshop_auth_business')->insert(['wanlshop_auth_id' => $ids]);
                    //授权书
                    Db::name('wanlshop_auth_accredit')->insert(['wanlshop_auth_id' => $ids]);
                    //授权书
                    Db::name('wanlshop_auth_accredit')->insert(['wanlshop_auth_id' => $ids]);

                }

            }
            Db::commit();
        } catch (ValidateException|PDOException|Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }
        if (false === $result) {
            $this->error(__('No rows were updated'));
        }
        $this->success();

    }
    // 信息审核
    public function information($ids = null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $adminIds = $this->getDataLimitAdminIds();
        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
            $this->error(__('You have no permission'));
        }
        if (false === $this->request->isPost()) {
            $this->view->assign('row', $row);
            return $this->view->fetch();
        }
        $status = $this->request->param('status');
        $params = $this->request->post('row/a');
        $staff_id = $this->auth->getUserInfo()['staff_id'];

        $result = false;
        Db::startTrans();
        try {
            //是否采用模型验证

            if($status == 1){
                $params['verify'] = 3;
                $params['auditsuccessfultime'] = time();
                $params['examineid'] = $staff_id;
            }
            $result = $row->save($params);
            Db::commit();
        } catch (ValidateException|PDOException|Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }
        if (false === $result) {
            $this->error(__('No rows were updated'));
        }
        $this->success();
    }

    public function finance($ids = null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $adminIds = $this->getDataLimitAdminIds();
        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
            $this->error(__('You have no permission'));
        }
        if (false === $this->request->isPost()) {
            $model = new \app\admin\model\shop\Financial();
            $editlist =  $model->where('wanlshop_auth_id',$ids)->find();
            $row['verify'] =    $editlist['verify'];
            $this->view->assign('row', $row);
            return $this->view->fetch();
        }
        $status = $this->request->param('status');
        $params = $this->request->post('row/a');

        $staff_id = $this->auth->getUserInfo()['staff_id'];
        $result = false;
        Db::startTrans();
        try {
            //是否采用模型验证
            $model = new \app\admin\model\shop\Financial();
            $editlist =  $model->where('wanlshop_auth_id',$ids)->find();
            if($status == 1){
                $params['verify'] = 2;
                $params['examinetime'] = time();
                $params['examineid'] = $staff_id;
            }
            $result =  $editlist->save($params);
            Db::commit();
        } catch (ValidateException|PDOException|Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }
        if (false === $result) {
            $this->error(__('No rows were updated'));
        }
        $this->success();
    }
    public function selection($ids = null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $adminIds = $this->getDataLimitAdminIds();
        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
            $this->error(__('You have no permission'));
        }
        if (false === $this->request->isPost()) {
            $row = DB::name('wanlshop_auth a')->join('wanlshop_auth_selection s','s.wanlshop_auth_id = a.id','left')->where('a.id',$ids)->find();
            $this->view->assign('row', $row);
            return $this->view->fetch();
        }
        $status = $this->request->param('status');
        $params = $this->request->post('row/a');

        $staff_id = $this->auth->getUserInfo()['staff_id'];
        $result = false;
        Db::startTrans();
        try {
            //是否采用模型验证
            $model = new \app\admin\model\shop\Selection();
            $editlist =  $model->where('wanlshop_auth_id',$ids)->find();
            if($status == 1){
                $params['verify'] = 2;
                $params['examinetime'] = time();
                $params['examineid'] = $staff_id;
            }
            $result =  $editlist->save($params);
            Db::commit();
        } catch (ValidateException|PDOException|Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }
        if (false === $result) {
            $this->error(__('No rows were updated'));
        }
        $this->success();
    }
    public function design($ids = null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $adminIds = $this->getDataLimitAdminIds();
        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
            $this->error(__('You have no permission'));
        }
        if (false === $this->request->isPost()) {
            $row = DB::name('wanlshop_auth a')->join('wanlshop_auth_design s','s.wanlshop_auth_id = a.id','left')->where('a.id',$ids)->find();
            $this->view->assign('row', $row);
            return $this->view->fetch();
        }
        $status = $this->request->param('status');
        $params = $this->request->post('row/a');
        $staff_id = $this->auth->getUserInfo()['staff_id'];
        $result = false;
        Db::startTrans();
        try {
            //是否采用模型验证
            $model = new \app\admin\model\shop\Design();
            $editlist =  $model->where('wanlshop_auth_id',$ids)->find();
            if($status == 1){
                $params['verify'] = 2;
                $params['examinetime'] = time();
                $params['examineid'] = $staff_id;
            }
            unset($params['staff_id']);
            unset($params['address']);
            $result =  $editlist->save($params);
            Db::commit();
        } catch (ValidateException|PDOException|Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }
        if (false === $result) {
            $this->error(__('No rows were updated'));
        }
        $this->success();
    }
    public function goods($ids = null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $adminIds = $this->getDataLimitAdminIds();
        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
            $this->error(__('You have no permission'));
        }
        if (false === $this->request->isPost()) {
            $row = DB::name('wanlshop_auth a')->join('wanlshop_auth_goods s','s.wanlshop_auth_id = a.id','left')->where('a.id',$ids)->find();
            $this->view->assign('row', $row);
            return $this->view->fetch();
        }
        $status = $this->request->param('status');
        $params = $this->request->post('row/a');
        $order = $this->request->post('order');

        $staff_id = $this->auth->getUserInfo()['staff_id'];
        $result = false;
        Db::startTrans();
        try {
            //是否采用模型验证
            $model = new \app\admin\model\shop\Goods();
            $editlist =  $model->where('wanlshop_auth_id',$ids)->find();
            if($status == 1){
                $params['verify'] = 2;
                $params['examinetime'] = time();
                $params['order'] = $order;
                $params['examineid'] = $staff_id;
            }
            $result =  $editlist->save($params);
            Db::commit();
        } catch (ValidateException|PDOException|Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }
        if (false === $result) {
            $this->error(__('No rows were updated'));
        }
        $this->success();
    }
    public function supply($ids = null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $adminIds = $this->getDataLimitAdminIds();
        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
            $this->error(__('You have no permission'));
        }
        if (false === $this->request->isPost()) {
            $model = new \app\admin\model\shop\Supply();
            $row = DB::name('wanlshop_auth a')->join('wanlshop_auth_supply s','s.wanlshop_auth_id = a.id','left')->where('a.id',$ids)->find();
            $this->view->assign("supplyList", $model->getsupplyList());
            $this->view->assign('row', $row);
            return $this->view->fetch();
        }
        $status = $this->request->param('status');
        $params = $this->request->post('row/a');
        $supply = $this->request->post('supply');
        $tracking = $this->request->post('tracking');
        $result = false;
        $staff_id = $this->auth->getUserInfo()['staff_id'];
        Db::startTrans();
        try {
            //是否采用模型验证
            $model = new \app\admin\model\shop\Supply();
            $editlist =  $model->where('wanlshop_auth_id',$ids)->find();
            if($status == 1){
                $params['verify'] = 2;
                $params['examinetime'] = time();
                $params['supply'] = $supply;
                $params['tracking'] = $tracking;
                $params['examineid'] = $staff_id;
            }
            $result =  $editlist->save($params);
            Db::commit();
        } catch (ValidateException|PDOException|Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }
        if (false === $result) {
            $this->error(__('No rows were updated'));
        }
        $this->success();
    }
    public function train($ids = null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $adminIds = $this->getDataLimitAdminIds();
        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
            $this->error(__('You have no permission'));
        }
        if (false === $this->request->isPost()) {
            $row = DB::name('wanlshop_auth a')->join('wanlshop_auth_train s','s.wanlshop_auth_id = a.id','left')->where('a.id',$ids)->find();
            $this->view->assign('row', $row);
            return $this->view->fetch();
        }
        $status = $this->request->param('status');
        $params = $this->request->post('row/a');
        $traintime = $this->request->post('traintime');
        $result = false;
        $staff_id = $this->auth->getUserInfo()['staff_id'];
        Db::startTrans();
        try {
            //是否采用模型验证
            $model = new \app\admin\model\shop\Train();
            $editlist =  $model->where('wanlshop_auth_id',$ids)->find();
            if($status == 1){
                $params['verify'] = 2;
                $params['examinetime'] = time();
                $params['traintime'] = $traintime;
                $params['examineid'] = $staff_id;
            }
            $result =  $editlist->save($params);
            Db::commit();
        } catch (ValidateException|PDOException|Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }
        if (false === $result) {
            $this->error(__('No rows were updated'));
        }
        $this->success();
    }
    public function activity($ids = null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $adminIds = $this->getDataLimitAdminIds();
        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
            $this->error(__('You have no permission'));
        }
        if (false === $this->request->isPost()) {
            $row = DB::name('wanlshop_auth a')->join('wanlshop_auth_activity s','s.wanlshop_auth_id = a.id','left')->where('a.id',$ids)->find();
            $this->view->assign('row', $row);
            return $this->view->fetch();
        }
        $status = $this->request->param('status');
        $params = $this->request->post('row/a');
        $result = false;
        $staff_id = $this->auth->getUserInfo()['staff_id'];
        Db::startTrans();
        try {
            //是否采用模型验证
            $model = new \app\admin\model\shop\Activity();
            $editlist =  $model->where('wanlshop_auth_id',$ids)->find();
            if($status == 1){
                $params['verify'] = 2;
                $params['examinetime'] = time();
                $params['examineid'] = $staff_id;
            }
            $result =  $editlist->save($params);
            Db::commit();
        } catch (ValidateException|PDOException|Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }
        if (false === $result) {
            $this->error(__('No rows were updated'));
        }
        $this->success();
    }
    public function business($ids = null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $adminIds = $this->getDataLimitAdminIds();
        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
            $this->error(__('You have no permission'));
        }
        if (false === $this->request->isPost()) {
            $row = DB::name('wanlshop_auth a')->join('wanlshop_auth_business s','s.wanlshop_auth_id = a.id','left')->where('a.id',$ids)->find();
            $this->view->assign('row', $row);
            return $this->view->fetch();
        }
        $status = $this->request->param('status');
        $params = $this->request->post('row/a');
        $starttime = $this->request->post('starttime');
        $staff_id = $this->auth->getUserInfo()['staff_id'];
        $result = false;
        Db::startTrans();
        try {
            //是否采用模型验证
            $model = new \app\admin\model\shop\Business();
            $editlist =  $model->where('wanlshop_auth_id',$ids)->find();
            if($status == 1){
                $params['verify'] = 2;
                $params['examinetime'] = time();
                $params['starttime'] = $starttime;
                $params['examineid'] = $staff_id;
            }
            $result =  $editlist->save($params);
            Db::commit();
        } catch (ValidateException|PDOException|Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }
        if (false === $result) {
            $this->error(__('No rows were updated'));
        }
        $this->success();
    }
    public function accredit($ids = null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $adminIds = $this->getDataLimitAdminIds();
        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
            $this->error(__('You have no permission'));
        }
        if (false === $this->request->isPost()) {
            $row = DB::name('wanlshop_auth a')->join('wanlshop_auth_accredit s','s.wanlshop_auth_id = a.id','left')->where('a.id',$ids)->find();
            $this->view->assign('row', $row);
            return $this->view->fetch();
        }
        $staff_id = $this->auth->getUserInfo()['staff_id'];
        $status = $this->request->param('status');
        $params = $this->request->post('row/a');
        $result = false;
        Db::startTrans();
        try {
            //是否采用模型验证
            $model = new \app\admin\model\shop\Accredit();
            $editlist =  $model->where('wanlshop_auth_id',$ids)->find();
            if($status == 1){
                $params['verify'] = 2;
                $params['examinetime'] = time();
                $params['examineid'] = $staff_id;
            }
            $result =  $editlist->save($params);
            Db::commit();
        } catch (ValidateException|PDOException|Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }
        if (false === $result) {
            $this->error(__('No rows were updated'));
        }
        $this->success();
    }
    public function reject(){
        $ids = $this->request->param('ids');
        $type = $this->request->param('type');
        $financialModel = new \app\admin\model\shop\Financial();
        $selectionModel = new \app\admin\model\shop\Selection();
        $designModel = new \app\admin\model\shop\Design();
        $goodsModel = new \app\admin\model\shop\Goods();
        $supplyModel = new \app\admin\model\shop\Supply();
        $trainModel = new \app\admin\model\shop\Train();
        $activityModel = new \app\admin\model\shop\Activity();
        $businessModel = new \app\admin\model\shop\Business();
        $accreditModel = new \app\admin\model\shop\Accredit();
        $staff_id = $this->auth->getUserInfo()['staff_id'];
        if (false === $this->request->isPost()) {
            $this->view->assign('ids', $ids);
            $this->view->assign('type', $type);
            if ($type == 'information'){
                $this->model->where('id',$ids)->update(['verify'=>4]);
            }
            if ($type == 'finance'){
                $financialModel->where('wanlshop_auth_id',$ids)->update(['verify'=>3,'examineid'=>$staff_id]);
            }
            if ($type == 'selection'){
                $selectionModel->where('wanlshop_auth_id',$ids)->update(['verify'=>3 ,'examineid'=>$staff_id]);
            }
            if ($type == 'design'){
                $designModel->where('wanlshop_auth_id',$ids)->update(['verify'=>3 ,'examineid'=>$staff_id]);
            }
            if ($type == 'goods'){
                $goodsModel->where('wanlshop_auth_id',$ids)->update(['verify'=>3 ,'examineid'=>$staff_id]);
            }
            if ($type == 'supply'){
                $supplyModel->where('wanlshop_auth_id',$ids)->update(['verify'=>3,'examineid'=>$staff_id]);
            }
            if ($type == 'train'){
                $trainModel->where('wanlshop_auth_id',$ids)->update(['verify'=>3,'examineid'=>$staff_id]);
            }
            if ($type == 'activity'){
                $activityModel->where('wanlshop_auth_id',$ids)->update(['verify'=>3,'examineid'=>$staff_id]);
            }
            if ($type == 'business'){
                $businessModel->where('wanlshop_auth_id',$ids)->update(['verify'=>3,'examineid'=>$staff_id]);
            }
            if ($type == 'accredit'){
                $accreditModel->where('wanlshop_auth_id',$ids)->update(['verify'=>3,'examineid'=>$staff_id]);
            }
            return $this->view->fetch();
        }
        $params = $this->request->post();
        if ($type == 'information'){
            $this->model->where('id',$ids)->update(['refuse'=>$params['reason'],'refuseimage'=>$params['receipimages']]);
        }
        if ($type == 'finance'){
            $res =  $financialModel->where('wanlshop_auth_id',$ids)->update(['refuse'=>$params['reason'],'refuseimage'=>$params['receipimages']]);
        }
        if ($type == 'selection'){
            $res =  $selectionModel->where('wanlshop_auth_id',$ids)->update(['refuse'=>$params['reason'],'refuseimage'=>$params['receipimages']]);
        }
        if ($type == 'design'){
            $res =  $designModel->where('wanlshop_auth_id',$ids)->update(['refuse'=>$params['reason'],'refuseimage'=>$params['receipimages']]);
        }
        if ($type == 'goods'){
            $res =  $goodsModel->where('wanlshop_auth_id',$ids)->update(['refuse'=>$params['reason'],'refuseimage'=>$params['receipimages']]);
        }
        if ($type == 'supply'){
            $res =  $supplyModel->where('wanlshop_auth_id',$ids)->update(['refuse'=>$params['reason'],'refuseimage'=>$params['receipimages']]);
        }
        if ($type == 'train'){
            $res =  $trainModel->where('wanlshop_auth_id',$ids)->update(['refuse'=>$params['reason'],'refuseimage'=>$params['receipimages']]);
        }
        if ($type == 'activity'){
            $res =  $activityModel->where('wanlshop_auth_id',$ids)->update(['refuse'=>$params['reason'],'refuseimage'=>$params['receipimages']]);
        }
        if ($type == 'business'){
            $res =  $businessModel->where('wanlshop_auth_id',$ids)->update(['refuse'=>$params['reason'],'refuseimage'=>$params['receipimages']]);
        }
        if ($type == 'accredit'){
            $res =  $accreditModel->where('wanlshop_auth_id',$ids)->update(['refuse'=>$params['reason'],'refuseimage'=>$params['receipimages']]);
        }
        $this->success();
    }
}
